/*
 * @Author: egg1bro
 * @Date: 2023-01-09 00:11:30
 * @LastEditTime: 2023-02-01 13:29:58
 * @LastEditors: egg1bro
 * @Description: 
 * @FilePath: \team-graduation-design\src\stores\updateUserInfo.js
 * 可以输入预定的版权声明、个性签名、空行等
 */
import { defineStore } from 'pinia'
import {
    reqUpdateUserDesc, reqUpdateUserSex, reqUpdateUserName, reqUpdateUserPhone, reqGetSmsByToken,
    reqVerifySmsToResetPasswordPage, reqResetUserPassword, reqUpdateUserPassword
} from '@/api/index'
import router from '@/router/index'
export const useUpdateUserInfo = defineStore('updateUserInfo', () => {

    // 更新用户签名方法
    const getUpdateUserDesc = async (params = {}) => {
        let result = await reqUpdateUserDesc(params)
        if (result.status == 200) {
            console.log(result.message);
            router.push('/personInfo')
        } else {
            console.log(result.message);
        }
    }

    // 更新用户性别方法
    const getUpdateUserSex = async (params = {}) => {
        let result = await reqUpdateUserSex(params)
        if (result.status == 200) {
            console.log(result.message);
            router.push('/personInfo')
        } else {
            console.log(result.message);
        }
    }
    // 更新用户名字方法
    const getUpdateUserName = async (params = {}) => {
        let result = await reqUpdateUserName(params)
        // console.log(result, 'result');
        if (result.status == 200) {
            console.log(result.message);
            router.push('/personInfo')
        } else {
            console.log(result.message);
        }
    }

    // 更新用户绑定手机号方法
    const getUpdateUserPhone = async (params = {}) => {
        let result = await reqUpdateUserPhone(params)
        if (result.code == 200) {
            console.log(result.msg);
            router.push('/manageAccount')
        } else {
            console.log(result.msg);
        }
    }

    // 获取手机验证码
    const getSmsByToken = async (phone) => {
        await reqGetSmsByToken(phone)
    }

    // 校验手机验证码接口
    const getVerifySms = async (params = {}) => {
        let result = await reqVerifySmsToResetPasswordPage(params)
        if (result.code == 200) {
            console.log(result.msg);
            router.push('/resetPassword')
        } else {
            console.log(result.msg);
        }
    }

    // reset用户密码接口
    const getResetUserPassword = async (params = {}) => {
        let result = await reqResetUserPassword(params)
        if (result.code == 200) {
            console.log(result.msg);
            router.push('/login')
        } else {
            console.log(result.msg);
        }
    }

    // updateUserPassword
    const getUpdateUserPassword = async (params = {}) => {
        let result = await reqUpdateUserPassword(params)
        if (result.code == 200) {
            console.log(result.msg);
        } else {
            console.log(result.msg);
        }
    }
    return {
        getUpdateUserDesc, getUpdateUserSex, getUpdateUserName, getUpdateUserPhone, getSmsByToken, getVerifySms
        , getResetUserPassword, getUpdateUserPassword
    }
})